<?php

// 应用公共函数库文件

use app\admin\service\Auth;
use think\Db;
/**
 * 验证指定url是否有访问权限
 * @param string|array $url
 * @param bool $strict 严格模式
 * @return bool
 */
function checkPrivilege($url, $strict = true)
{
    try {
        return Auth::getInstance()->checkPrivilege($url, $strict);
    } catch (\Exception $e) {
        return false;
    }
}

function gettime($time){
     return date('Y-m-d :H:i:s',$time);
}
function getImage($id)
{
    $img = Db::name('upload_file')->where('file_id', $id)->find();
    if ($img['storage'] !== 'local') {
        return $img['file_url'] . '/' . $img['file_name'];
    } else {
        return base_url() . 'uploads/' . $img['file_name'];
    }
}

function  getParent($pid){
    $name=db('agent')->where('agent_id',$pid)->field('company_name,real_name')->find();
    if (!empty($name['company_name'])){
        return $name['company_name'];
    }else{
        return  $name['real_name'];
    }
}

function getuInfo($id){
    $name=db('yonghui_user')->where('id',$id)->field('name')->find();
    return  $name['name'];

}
function getInfo($bankuaiId){
    $name=db('yonghui_plate')->where('id',$bankuaiId)->field('name')->find();

    return  $name['name'];

}
function getInfox($bankuaiId){
    $name=db('yonghui_project')->where('id',$bankuaiId)->field('name')->find();

    return  $name['name'];

}

function getluruname($id){
    $name=db('yonghui_user')->where('id',$id)->field('name')->find();
    return  $name['name'];
}
function getluruphone($id){
    $name=db('yonghui_user')->where('id',$id)->field('name,phone')->find();
    return  $name['phone'];
}

function getgenjloupanname($id){
    $name=db('yonghui_building')->where('id',$id)->field('name')->find();
    return  $name['name'];
}
function getImages($customerId,$type){

    $imageids=Db::name('yonghui_follow')->where(['customerId'=>$customerId,'type'=>$type])->find();
    $imageInfos=Db::name('upload_file')->where('file_id','in',json_decode($imageids['imageIds'],true))->select();
    $arr=[];
    if($imageInfos){
        foreach($imageInfos as $k=>$v){
            $arr[]=$v['file_url'].'/'.$v['file_name'];
        }
    }
    return $arr;
}
function getContent($customerId,$type){

    $imageids=Db::name('yonghui_follow')->where(['customerId'=>$customerId,'type'=>$type])->find();
    return $imageids['content'];
}

